<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>东财个股资金流</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			//p {margin:5px}
			//ul {margin:1px}			
			//h4 {margin:1px}	
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}			
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			window.onload = function() {			
			getSource(1);
			changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource(0);					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
						
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "480px";	
				obj1.style.height= "620px";		
				obj1.style.fontSize="12px";						
			}	
						
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}						
										
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i] == undefined){
						break;
					}
					alist[i].style.color = "#d2d2d3"; //给所有a标签赋原色
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
			function NumberTransform(num) { 
				var result = num;
               if(Math.abs(num) > 100000000)
			   {
			    result = num / 100000000;
				result = result.toFixed(2) + "亿";
			   }
				else if(Math.abs(num) > 10000)
			   {
			    result = num/10000;
				result = result.toFixed(2) + "万";
			   }				   
               return result;  
			};	
			
			var fid = "";
			var y = 0;
			var gl = "";  //高亮
			function getSource(s) {			    
				if(s != 0){
				y = s}
				div = document.getElementById('towrite');				
				var p1 = "<a href='javascript:void(0)' id='px1' onclick='getSource(" + "\"1\"" + ")'>" + "涨幅" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='px2' onclick='getSource(" + "\"2\"" + ")'>" + "主力净额" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='px3' onclick='getSource(" + "\"3\"" + ")'>" + "主力净占比" + "</a>";
				var p4 = "<a href='javascript:void(0)' id='px4' onclick='getSource(" + "\"4\"" + ")'>" + "超大单净额" + "</a>";
				var p5 = "<a href='javascript:void(0)' id='px5' onclick='getSource(" + "\"5\"" + ")'>" + "超大单净占比" + "</a>";
				var p6 = "<a href='javascript:void(0)' id='px6' onclick='getSource(" + "\"6\"" + ")'>" + "大单净额" + "</a>";
				var p7 = "<a href='javascript:void(0)' id='px7' onclick='getSource(" + "\"7\"" + ")'>" + "大单净占比" + "</a>";
				div.innerHTML = '<h4>东财个股资金流</h4>' + '<b>（排序：' + p1 + p2 + p3 + p4 + p5 + '<br>' + p6 + p7 + '）</b>';
				
				aObj = document.getElementById('px' + y);
				gl = aObj.innerText;
				aObj.innerText = aObj.innerText + "↓";
				aObj.style.color = "#FFA07A";				
				if(y == 1)
				{
					fid = "f3";					
				}
				else if(y == 2)
				{
					fid = "f62";
				}
				else if(y == 3)
				{
					fid = "f184";
				}
				else if(y == 4)
				{
					fid = "f66";
				}
				else if(y == 5)
				{
					fid = "f69";
				}
				else if(y == 6)
				{
					fid = "f72";
				}
				else if(y == 7)
				{
					fid = "f75";
				}
			
				var url = "http://push2.eastmoney.com/api/qt/clist/get?cb=jQuery112308584254039229833_1634203729603&fid=" + fid + "&po=1&pz=50&pn=1&np=1&fltt=2&invt=2&ut=b2884a393a59ad64002292a3e90d46a5&fs=m:0+t:6+f:!2,m:0+t:13+f:!2,m:0+t:80+f:!2,m:1+t:2+f:!2,m:1+t:23+f:!2&fields=f12,f14,f2,f3,f62,f184,f66,f69,f72,f75,f78,f81,f84,f87,f204,f205,f124,f1,f13"
				//document.write(url);
				if (window.XMLHttpRequest) {
				xmlHttp1 = new XMLHttpRequest();				
				} else {
				xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");				
				}					
				xmlHttp1.onreadystatechange = writeSource;
				xmlHttp1.open("GET", url, true);				
				//xmlHttp.withCredentials = true
				xmlHttp1.send(null);				
			}
						
			function writeSource() { 
			if (xmlHttp1.readyState == 4) {         
				var data = xmlHttp1.responseText	
				//document.write(data);
				data = data.replace(/ /g,"").match(/\"diff\":(\S*)\}\]\}\}\);/)[1];	
				data = "{\"data\":" + data + "}]}";
				//document.write(data);
				
				var transform_aa = [           
				{"tag":"p", children:function(){return(json2html.transform(this.data, transform_bb));}}
				];				
				
				m = 0;
				var transform_bb= 				
				{"tag":"ul", children:[	
				{"tag":"li", children:function(){
					m++;				
					return(
					"<a href=http://www.treeid/code_" +
						this.f12 + " id='gg' onclick='changeCss(this,this.id)'>" + m + ". " + 						
						this.f12 + "&nbsp;&nbsp;" + 
						this.f14 + "&nbsp;&nbsp;" +
						" 涨幅：" + this.f3 + "%&nbsp;&nbsp;<br>" + 
						" 主力净额：" + NumberTransform(this.f62) + "&nbsp;&nbsp;" +
						" 主力净占比：" + this.f184 + "%&nbsp;&nbsp;<br>" +
						" 超大单净额：" + NumberTransform(this.f66) + "&nbsp;&nbsp;" +
						" 超大单净占比：" + this.f69 + "%&nbsp;&nbsp;<br>" +
						" 大单净额：" + NumberTransform(this.f72) + "&nbsp;&nbsp;" +
						" 大单净占比：" + this.f75 + "%&nbsp;&nbsp;<br>" +
						" 中单净额：" + NumberTransform(this.f78) + "&nbsp;&nbsp;" +
						" 中单净占比：" + this.f81 + "%&nbsp;&nbsp;<br>" +
						" 小单净额：" + NumberTransform(this.f84) + "&nbsp;&nbsp;" +
						" 小单净占比：" + this.f87 + "%&nbsp;&nbsp;" +
						 "</a>" 					
					);
				}}							
				]};  
				
				var html = json2html.transform(data, transform_aa);		
				div = document.getElementById('towrite');								
				div.innerHTML = div.innerHTML + "<span id='gg'>" + html + "</span>";
				
				//高亮
				var content = document.getElementById("gg").innerHTML;
				var reg = new RegExp("( " + gl + ")", "g");  
				var str = content;  
				var newstr = str.replace(reg, "<font color=#FF6633>$1</font>");
				document.getElementById("gg").innerHTML = newstr;

				}
			}
			
		</script>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>		
	</body>
</html>